package com.tr.rentcar.controller.userc;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.tr.rentcar.model.bean.FeedBack;
import com.tr.rentcar.model.bean.FeedBackStyle;
import com.tr.rentcar.model.bean.User;
import com.tr.rentcar.model.dao.FeedbackDao;
import com.tr.rentcar.model.dao.FeedbackStyleDao;

/**
 * Servlet implementation class FeedbackController
 */
@WebServlet("/user/feedback")
public class FeedbackController extends HttpServlet {
	private static final long serialVersionUID = 1L;
	FeedbackStyleDao fbd=new FeedbackStyleDao();
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		User user=(User) request.getSession().getAttribute("userinfo");
		String name=user.getUname();
		request.setAttribute("name", name);
		try {
			List<FeedBackStyle> lfb=fbd.findStyle();
			System.out.println(lfb);
			request.setAttribute("lfb", lfb);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		request.getRequestDispatcher("/WEB-INF/jsp/feedback.jsp").forward(request, response);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		FeedbackDao fd=new FeedbackDao();
		String style=req.getParameter("first"); 
		String name=req.getParameter("name");
		String content=req.getParameter("content");
		User user=(User) req.getSession().getAttribute("userinfo");
		String name1=user.getUname();
		String btel=user.getUtel();
		try {
			Integer bsid=fbd.findStyleId(style).getBsId();
			fd.insertFeedback(content, bsid, name1, btel);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		doGet(req,resp);
	}

}
